<html>
<head><meta charset="utf-8"><title>simplified struct init · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html">simplified struct init</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227062867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227062867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manuel Drehwald <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227062867">(Feb 20 2021 at 03:49)</a>:</h4>
<p>I would like to ask about a new way to initialize structs.<br>
Say we have </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">Struct</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="n">a</span>: <span class="nc">int</span><span class="p">,</span><span class="w"></span>
<span class="n">b</span>: <span class="nc">int</span><span class="p">,</span><span class="w"></span>
<span class="n">c</span>: <span class="nc">int</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>and we have already defined b and c. Than we currently can create a new Foo by writing </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="n">a</span>: <span class="mi">42</span><span class="p">,</span><span class="w"></span>
<span class="n">b</span><span class="p">,</span><span class="w"></span>
<span class="n">c</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>If we have created f: Foo before, we can also write:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="n">a</span>: <span class="mi">42</span><span class="p">,</span><span class="w"></span>
<span class="o">..</span><span class="n">f</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Now I wanted to ask about simplifying the case above where we defined b and c locally into:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="n">a</span>: <span class="mi">42</span><span class="p">,</span><span class="w"></span>
<span class="o">..</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>In this case the local values of b and c should be inserted. <br>
I would argue that this feature makes sense, since Foo:new(b,c) constructor functions are quite common, afaik.<br>
First you check that the given input is in some allowed range, set the omitted inputs to some reasonable default and if all values are fine you just create the struct and return it.<br>
We already have the .. Syntax for "copy-constructors" which are probably less used that the shown "constructor from variables".<br>
I know that Rust is about being explicit, but I would argue that <code> ..</code> is not hiding relevant information compared to the two available other initialization methods. At least for me it feels natural and I expected it to be available after learning about <code>..f</code>.</p>
<p>Do you think it makes sense to add an RFC for that?</p>



<a name="227063085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063085">(Feb 20 2021 at 03:52)</a>:</h4>
<p>i'm not a fan of this for a few reasons, but they boil down to its unclear which variables from the scope are being used.</p>



<a name="227063144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063144">(Feb 20 2021 at 03:53)</a>:</h4>
<p>i dont think there's currently a way in rust to use variables without typing their names, and this would add that.</p>



<a name="227063197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063197">(Feb 20 2021 at 03:54)</a>:</h4>
<p>This might be a better fit for <a href="http://internals.rust-lang.org">internals.rust-lang.org</a> . In particular I think <a href="https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-sugar-for-default-default/13234">https://internals.rust-lang.org/t/pre-pre-rfc-syntactic-sugar-for-default-default/13234</a> is a conflicting proposal that is worth a read to see whether you prefer for this corner of the syntax</p>



<a name="227063275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063275">(Feb 20 2021 at 03:55)</a>:</h4>
<p>I'm with Thom</p>



<a name="227063483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063483">(Feb 20 2021 at 03:58)</a>:</h4>
<p>It would be a bit weird that adding a member <code>x</code> to <code>Foo</code> causes an undefined variable reference of <code>x</code> in <code>fn mk_foo() -&gt; Foo { Foo {..} }</code> that never mentions <code>x</code></p>



<a name="227063517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063517">(Feb 20 2021 at 03:59)</a>:</h4>
<p>naw you could make the error message there fairly good</p>



<a name="227063570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063570">(Feb 20 2021 at 04:00)</a>:</h4>
<p>i think that the reason to not do it is different from a potentially bad error message</p>



<a name="227063620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063620">(Feb 20 2021 at 04:01)</a>:</h4>
<p>including, but not limited to, the fact that if you add a field to a struct suddenly you might grab in new variables in other code elsewhere using that type with the {..} syntax</p>



<a name="227063650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063650">(Feb 20 2021 at 04:01)</a>:</h4>
<p>oh yeah, that's stability breaking in all sorts of nasty ways</p>



<a name="227063658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063658">(Feb 20 2021 at 04:01)</a>:</h4>
<p>and if those are Copy fields, then you wouldn't even get told (if they're non-copy fields you'll <em>probably</em> get a sudden use-after-move error)</p>



<a name="227063730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manuel Drehwald <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063730">(Feb 20 2021 at 04:02)</a>:</h4>
<p>Well I understand that ..f hides the variable names and {.. b, c,} hides where those b and c values exactly come from.<br>
My proposal would therefore hide which variables are used plus where those variables come from.<br>
So I understand that it could accumulate complexity. <br>
I just wanted to ask about opinions since both other methods are available and as mentioned it felt natural to me.<br>
But I'm not into rustc, so I wasn't aware of all the pitfalls it could bring. <br>
Thanks for your explanations :)</p>



<a name="227063782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063782">(Feb 20 2021 at 04:03)</a>:</h4>
<p>Also, this isn't the main source of boilerplate in these constructor functions IMO, you still have to write out the function with the types and names same as the struct and so on</p>



<a name="227063790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063790">(Feb 20 2021 at 04:03)</a>:</h4>
<p>I absolutely want .. to be better, and apparently a lot of others do (that thread linked had 119 posts), but i think this is a little too much unspoken magic</p>



<a name="227063885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Manuel Drehwald <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063885">(Feb 20 2021 at 04:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> Thank you for the link to the internals, I just followed the links from here: <a href="https://github.com/rust-lang/rust/blob/25f39fe80293f77bd86f64a1261a3e2c0ca23847/CONTRIBUTING.md">https://github.com/rust-lang/rust/blob/25f39fe80293f77bd86f64a1261a3e2c0ca23847/CONTRIBUTING.md</a> to zulip. <br>
But next time I will start there.</p>
<p>The other proposal there also sounds interesting.</p>



<a name="227063895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063895">(Feb 20 2021 at 04:06)</a>:</h4>
<p>Oh no don't worry in terms of protocol! Asking a question in #general is entirely fine.</p>



<a name="227063949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227063949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227063949">(Feb 20 2021 at 04:06)</a>:</h4>
<p>though in general the zulip and the forums cater to slightly different crowds, it's not 100% crossover</p>



<a name="227064052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227064052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227064052">(Feb 20 2021 at 04:08)</a>:</h4>
<p>Yeah I don't mean to say this is off topic, only that this kind of question comes up more often on IRLO so you will probably get more useful responses</p>



<a name="227074960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227074960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227074960">(Feb 20 2021 at 07:52)</a>:</h4>
<p>Another reason is that I would expect .. to do something different: fill in default values, not values from locals named like the fields.</p>



<a name="227096822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227096822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227096822">(Feb 20 2021 at 15:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/122651-general/topic/simplified.20struct.20init/near/227063483">said</a>:</p>
<blockquote>
<p>It would be a bit weird that adding a member <code>x</code> to <code>Foo</code> causes an undefined variable reference of <code>x</code> in <code>fn mk_foo() -&gt; Foo { Foo {..} }</code> that never mentions <code>x</code></p>
</blockquote>
<p>or worse, you could end up with <code>Foo</code> capturing an unrelated internal variable you had in scope:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">g</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">raw_mutex</span><span class="p">.</span><span class="n">lock</span><span class="p">();</span><span class="w"></span>
<span class="n">racy_stuff</span><span class="p">();</span><span class="w"></span>
<span class="k">if</span><span class="w"> </span><span class="n">condition</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">42</span><span class="p">;</span><span class="w"> </span><span class="c1">// field of Foo</span>
<span class="w">    </span><span class="n">consume</span><span class="p">(</span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">do_racy_thing_since_guard_was_not_dropped_yet</span><span class="p">();</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">drop</span><span class="p">(</span><span class="n">g</span><span class="p">);</span><span class="w"> </span><span class="c1">// release the lock</span>
<span class="w">    </span><span class="n">stuff</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Then adding some generic-compatible <code>g</code> field to <code>Foo</code> would suddenly lead to a data race <span aria-label="cold sweat" class="emoji emoji-1f630" role="img" title="cold sweat">:cold_sweat:</span>  (granted, this can also be interpreted as yet another instance where raw guards ought to be dropped explicitly).</p>



<a name="227098032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227098032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227098032">(Feb 20 2021 at 15:30)</a>:</h4>
<p>oh the things we'd put into rust2 if we knew at the time</p>



<a name="227098043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227098043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227098043">(Feb 20 2021 at 15:30)</a>:</h4>
<p>but explicit drops are bad for early returns, so there's that.</p>



<a name="227106693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/simplified%20struct%20init/near/227106693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/simplified.20struct.20init.html#227106693">(Feb 20 2021 at 17:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/simplified.20struct.20init/near/227098032">said</a>:</p>
<blockquote>
<p>oh the things we'd put into rust2 if we knew at the time</p>
</blockquote>
<p>Yeah, I was hinting at the "programmer good practices" more than a fully enforced language thing.</p>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/simplified.20struct.20init/near/227098043">said</a>:</p>
<blockquote>
<p>but explicit drops are bad for early returns, so there's that.</p>
</blockquote>
<p>True, it's definitely a good argument against generalizing that to too many types.</p>
<p>FWIW, here is what the fully paranoid API would look like (<em>à la</em> linear_types (modulo unwinding)):</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Mutex</span>::<span class="n">new</span><span class="p">(</span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m</span><span class="p">.</span><span class="n">with_lock</span><span class="p">(</span><span class="o">|</span><span class="k">mut</span><span class="w"> </span><span class="n">guard</span><span class="o">|</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">value</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">guard</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span>::<span class="n">core</span>::<span class="n">mem</span>::<span class="n">take</span><span class="p">(</span><span class="n">value</span><span class="p">);</span><span class="w"> </span><span class="c1">// compute some stuff out of the wrapped value</span>
<span class="w">    </span><span class="c1">// return ret; /* Uncomment to make compilation fail */</span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">token</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">guard</span><span class="p">.</span><span class="nb">drop</span><span class="p">();</span><span class="w"> </span><span class="c1">// we can release the drop early</span>
<span class="w">        </span><span class="c1">// do stuff with the lock released</span>
<span class="w">        </span><span class="cm">/* … */</span><span class="w"></span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">token</span><span class="p">.</span><span class="n">returning</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="o">*</span><span class="n">value</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="c1">// or late:</span>
<span class="w">    </span><span class="n">guard</span><span class="p">.</span><span class="nb">drop</span><span class="p">().</span><span class="n">returning</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span><span class="w"></span>
<span class="p">});</span><span class="w"></span>
<span class="fm">assert_eq!</span><span class="p">(</span><span class="n">v</span><span class="p">,</span><span class="w"> </span><span class="mi">42</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<ul>
<li><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=38fc68c01af1acff7cf2a21975c13c6e">Playground</a></li>
</ul>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>